package com.whw.springboot.bcucb.controller;




import com.whw.springboot.bcucb.entity.Download;
import com.whw.springboot.bcucb.entity.Message;
import com.whw.springboot.bcucb.service.DownloadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Api(tags = "下载记录")
@RestController
@RequestMapping("/api/Download")
public class DownloadController {
    @Resource
    private DownloadService downloadService;

    /**
     * 根据案例id查看下载记录
     */
    @ApiOperation(value = "根据案例id查看下载记录")
    @GetMapping(value = "/caseId")
    public Message<List<Download>> selectByCaseId( String caseId){
        return downloadService.selectByCaseId(caseId);
    }

    /**
     * 根据用户id查看下载记录
     */
    @ApiOperation(value = "根据用户id查看下载记录")
    @GetMapping(value = "/userId")
    public Message<List<Download>> selectByUserId( String userId){
        return downloadService.selectByUserId(userId);
    }

    /**
     * 根据用户id查看七天的下载记录
     */
    @ApiOperation(value = "根据用户id查看七天的下载记录")
    @GetMapping(value = "/userIdByDate")
    public Message<List<Download>> selectByUserIdAndDate(String userId){
        Date date = new Date();
        Date dateS=new Date(date.getTime() - (7 * 24 * 60 * 60 * 1000));
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
        return downloadService.selectByUserIdAndDate(dateFormat.format(date),dateFormat.format(dateS),userId);

    }

    /**
     * 根据案例id查看七天的下载记录
     */
    @ApiOperation(value = "根据案例id查看七天的下载记录")
    @GetMapping(value = "/caseIdByDate")
    public Message<List<Download>> selectByCaseIdAndDate(String caseId){
        Date date = new Date();
        Date dateS=new Date(date.getTime() - (7 * 24 * 60 * 60 * 1000));
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
        return downloadService.selectByCaseIdAndDate(dateFormat.format(date),dateFormat.format(dateS),caseId);

    }

    /**
     * 查看所有的下载记录
     */
    @ApiOperation(value = "查看所有的下载记录")
    @GetMapping(value = "/all")
    public Message<List<Download>> selectByAll(){
        return downloadService.selectByAll();
    }

    /**
     * 查看所有的七天的下载记录
     */
    @ApiOperation(value = "查看所有的七天的下载记录")
    @GetMapping(value = "/allDate")
    public Message<List<Download>> selectByAllAndDate(){
        Date date = new Date();
        Date dateS=new Date(date.getTime() - (7 * 24 * 60 * 60 * 1000));
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
        return downloadService.selectByAllAndDate(dateFormat.format(date),dateFormat.format(dateS));
    }


    /**
     * 增加下载数
     */
    @ApiOperation(value = "增加下载数")
    @PostMapping(value = "/")
    public Message<?> insertDownload( Download  download ){
        return downloadService.insert(download);
    }

    /**
     * 删除下载记录
     */
    @ApiOperation(value = "删除下载记录")
    @DeleteMapping(value = "/")
    public Message<?> deleteByDownloadId(int DownloadId){
        return downloadService.deleteByPrimaryKey(DownloadId);
    }

    /**
     * 修改案例下载记录
     */
    @ApiOperation(value = "修改案例下载记录")
    @PutMapping(value = "/")
    public Message<?> updateByDownloadId(Download  download){
        return downloadService.updateByPrimaryKey(download);
    }


}
